
<template>
  <el-upload v-model:file-list="fileList" class="upload-demo" :action= "uploadIp" multiple :headers="token1" :on-preview="handlePreview" :on-remove="handleRemove"  :on-exceed="handleExceed" :on-success="handleSuccess" :on-error="handleSuccess" with-credentials>
    <el-button type="primary">上传文件</el-button>
    <template #tip>
    </template>
  </el-upload>
</template>
<script setup lang="ts">
import {handleError, ref} from 'vue'
import {useUsersStore} from "../../store/userInfo.ts";
const store = useUsersStore();
const { name, role, token } = store;
import { ElMessage, ElMessageBox } from 'element-plus'
import type { UploadProps, UploadUserFile } from 'element-plus'
const fileList = ref<UploadUserFile[]>()
const uploadIp = import.meta.env.VITE_HTTP+"/system/upload/file"
const token1 = {
  token: store.token,
}
const handleRemove: UploadProps['onRemove'] = (file, uploadFiles) => {
  console.log(file, uploadFiles)
}

const handlePreview: UploadProps['onPreview'] = (uploadFile) => {
  console.log(uploadFile)
}

const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
  ElMessage.warning(
      `The limit is 3, you selected ${files.length} files this time, add up to ${
          files.length + uploadFiles.length
      } totally`
  )
}
const handleSuccess =(res)=>{
  if (res.code == 200){
    ElMessage.success(res.msg)
  }else {
    ElMessage.error(res.msg)
  }
}

</script>

<style scoped>

</style>
